package com.hz.erp.exception;

import com.hz.erp.constant.RetResponse;
import com.hz.erp.constant.RetResult;
import com.hz.erp.utils.JsonUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 柯鑫
 * @ClassName com.hz.erp.exception.ControllerExceptionHandler
 * @description 统一异常类处理
 * @create 2020年06月04日 16:39
 */
@ControllerAdvice
public class ControllerExceptionHandler {

    @ResponseBody
    @ExceptionHandler(RuntimeException.class)
    public RetResult<Map<String, Object>> handleUserNotExistsException(RuntimeException e){
        Map<String, Object> map = new HashMap<>();
        map.put("warning", "出错误了,请联系泓正技术人员处理!");
        map.put("message", e.getMessage());
        return RetResponse.makeErrRsp(JsonUtil.toJSON(map));
    }

}
